package com.cqemme.activitiservice.service.impl;

import com.cqemme.activitiservice.service.CommonService;
import com.cqemme.comm.constraint.DefaultValues;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * @author nejery
 */
@Slf4j
@Service
public class CommonServiceImpl implements CommonService {

    @Resource
    private RepositoryService repositoryService;

    @Override
    public String getOrgProcessDefinitionId(Integer orgId,  String type) {
        // 查询流程定义
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
                .processDefinitionCategory(DefaultValues.ACTIVITI_NAME_SPACE_PREFIX + orgId)
                .processDefinitionKey(type)
                .active()
                .latestVersion()
                .singleResult();

        if(null != processDefinition){
            return processDefinition.getId();
        }else{
            return null;
        }
    }
}
